package net.xdclass.controller;


import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.xdclass.enums.BizCodeEnum;
import net.xdclass.request.LockCouponRecordRequest;
import net.xdclass.service.CouponRecordService;
import net.xdclass.util.JsonData;
import net.xdclass.vo.CouponRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 孙浩
 * @since 2022-04-20
 */
@RestController
@RequestMapping("/api/coupon_record/v1")
public class CouponRecordController {

  @Autowired
  private CouponRecordService couponRecordService;

  @ApiOperation(value = "领取记录分页查询")
  @GetMapping("/page")
  public JsonData page(@ApiParam(value = "当前页") @RequestParam(value = "page", defaultValue = "1") int page,
                       @ApiParam(value = "当前页条数") @RequestParam(value = "size", defaultValue = "20") int size) {
    return JsonData.buildSuccess(couponRecordService.pageData(page, size));
  }


  @ApiOperation("查询优惠券记录信息")
  @GetMapping("/detail/{record_id}")
  public JsonData findUserCouponRecordById(@PathVariable("record_id") long recordId) {
    CouponRecordVo couponRecordVO = couponRecordService.findById(recordId);
    return couponRecordVO == null ? JsonData.buildResult(BizCodeEnum.COUPON_NO_EXITS) : JsonData.buildSuccess(couponRecordVO);
  }


  /**
   * 锁定优惠券使用记录
   */
  @PostMapping("/lock_records")
  public JsonData lockRecords(@RequestBody LockCouponRecordRequest couponRecordRequest){
    return couponRecordService.lockRecords(couponRecordRequest);
  }

}

